 --desarrollados para bases de datos postgreSQL
 --INSERT CLIENTES
 CREATE OR REPLACE FUNCTION  public."sp_insert_clientes" (CEDULA in character varying,
 NOMBRE in character varying,APELLIDO in character varying,DIRECCION in character varying,
 TELEFONO in character varying) RETURNS VOID AS
 $body$
 BEGIN
INSERT INTO public."Clientes"  ("txtCI","txtNombre","txtApellido","txtDireccion","txtNumTlfno") 
	VALUES (CEDULA,NOMBRE,APELLIDO,DIRECCION,TELEFONO); 
END;
$body$
LANGUAGE 'plpgsql' VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;

--INSERT PROVEEDORES
CREATE OR REPLACE FUNCTION sp_insert_proveedor(empresa character varying, contacto character varying, cargo character varying, direccion character varying, ciudad character varying, telefono1 character varying, telefono2 character varying, telefono3 character varying)
  RETURNS void AS
$BODY$
 BEGIN
INSERT INTO public."Proveedores"  ("txtNomEmpresa","txtNomContacto","txtCargoContacto","txtDireccion","txtCiudad","txtNumTlfno1","txtNumTlfno2","txtNumTlfno3") 
	VALUES (EMPRESA,CONTACTO,CARGO,DIRECCION,CIUDAD,TELEFONO1,TELEFONO2,TELEFONO3); 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_insert_proveedor(character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying)
  OWNER TO postgres;

--INSERT EMPLEADOS
CREATE OR REPLACE FUNCTION sp_insert_empleado(cedula character varying, nombre character varying, apellido character varying, direccion character varying, telefono1 character varying, telefono2 character varying)
  RETURNS void AS
$BODY$ BEGIN
INSERT INTO public."Empleados"  ("txtCIEmpleado","txtNombre","txtApellido","txtDireccion","txtNumTlfno1","txtNumTlfno2") 
	VALUES (CEDULA,NOMBRE,APELLIDO,DIRECCION,TELEFONO1,TELEFONO2); 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_insert_empleado(character varying, character varying, character varying, character varying, character varying, character varying)
  OWNER TO postgres;

--INSERT CREDENCIALES DEL EMPLEADO
CREATE OR REPLACE FUNCTION sp_insert_empleado_users(codigo integer, usuario character varying, passwd character varying, rol character varying)
  RETURNS void AS
$BODY$ BEGIN
INSERT INTO public."EMPLEADO_USERS"  ("numIDEmpleado","txtUser","txtPasswd","txtRol") 
	VALUES (CODIGO,USUARIO,PASSWD,ROL); 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_insert_empleado_users(integer, character varying, character varying, character varying)
  OWNER TO postgres;

--INSERT CATEGORIAS
CREATE OR REPLACE FUNCTION sp_insert_categorias(descripcion character varying, numgd double precision, numgcfinal double precision)
  RETURNS void AS
$BODY$ BEGIN
INSERT INTO public."Categorias"  ("txtNombreCategoria","numGDistribuidor","numGCF") 
	VALUES ($1,$2,$3); 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_insert_categorias(character varying, double precision, double precision)
  OWNER TO postgres;


--INSERTAR PRODUCTO
CREATE OR REPLACE FUNCTION sp_insert_producto(Producto character varying,Unidad character varying, 
numPC double precision, numPV double precision,numIDP int, numIDC int)
  RETURNS void AS
$BODY$ 
BEGIN
INSERT INTO public."Productos"  ("txtNomProducto","txtDescripUnid","numPrecioCosto","txtPrecioVF","numIDProveedor","numIDCategoria") 
	VALUES (Producto,Unidad,numPC,numPV,numIDP,numIDC); 
END;
$BODY$
  LANGUAGE plpgsql;

--INSERTAR PRODUCTO_INVENTARIO
CREATE OR REPLACE FUNCTION sp_insert_producto_inventario(numIDP int,numCM double precision, numCA double precision, dateFC character varying)
  RETURNS void AS
$BODY$ 
BEGIN
INSERT INTO public."PRODUCTO_INVENTARIO"  ("numIDProducto","numCantMin","numCantActual","dateFechaCompra") 
	VALUES (numIDP,numCM,numCA,dateFC); 
END;
$BODY$
  LANGUAGE plpgsql;
  
--INSERTAR FACTURA
CREATE OR REPLACE FUNCTION sp_insert_factura(numIDFact int,numIDCli int, numIDEmp int, frmpago character varying, numST double precision, estado character varying, dateFF character varying)
  RETURNS void AS
$BODY$ 
BEGIN
INSERT INTO public."Facturas"  ("numIDFactura","numIDCliente","numIDEmpleado","txtFormaPago","numSubTotal","txtEstado","dateFechaFactura") 
	VALUES ($1,$2,$3,$4,$5,$6,$7); 
END;
$BODY$
  LANGUAGE plpgsql;  

--INSERTAR FACTURA_DETALLE
CREATE OR REPLACE FUNCTION sp_insert_factura_detalle(numIDFact int,numIDProd int, numCant double precision, numPrecioU double precision)
  RETURNS void AS
$BODY$ 
BEGIN
INSERT INTO public."FACTURA_DETALLE"  ("numIDFactura","numIDProducto","numCantProducto","numPrecioUnit") 
	VALUES ($1,$2,$3,$4); 
END;
$BODY$
  LANGUAGE plpgsql;    